/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib.language3;

import java.util.Collection;

import ac.jp.u_tokyo.SyncLib.language.EvaluationFailedException;
import ac.jp.u_tokyo.SyncLib.language.GraphCombinatorBody;
import ac.jp.u_tokyo.SyncLib.language2.EqualExpr.EqualConstPart;

public abstract class ConstVarRefPart extends Part
{

	protected String _name;

	protected abstract ConstPart createConst();

	protected int _line;

	public ConstVarRefPart()
	{
		super();
	}

	private Part createActualPart(Collection<String> genericParas)
	{
		if (genericParas.contains(_name)) {
			return createConst();
		}
		else
			return new VarPart(new Var(_name, _line));
	}
	
	@Override
	public void addBody(GraphCombinatorBody body, Collection<String> genericParas, Var var)
			throws EvaluationFailedException
	{
		createActualPart(genericParas).addBody(body, genericParas, var);
		
	}

	@Override
	public Var getConnectionVar(Collection<String> genericParas)
			throws EvaluationFailedException
	{
		return createActualPart(genericParas).getConnectionVar(genericParas);
	}

	@Override
	public Collection<Var> getVarUsed(Collection<String> genericParas) throws EvaluationFailedException
	{
		return createActualPart(genericParas).getVarUsed(genericParas);
	}

}